﻿using System.Web;

namespace Sucdri.Infrastructure.Core.Context
{
    internal sealed class ServiceContext
    {
        public static readonly ServiceContext Current = new ServiceContext();

        public void Add(string key, object value)
        {
            ContextContainer.Add(key, value);
        }

        public bool Contains(string key)
        {
            return ContextContainer.Contains(key);
        }

        public void Remove(string key)
        {
            ContextContainer.Remove(key);
        }

        private static IContextContainer ContextContainer
        {
            get
            {
                if (HttpContext.Current == null)
                    return new WindowsContextContainer();
                return new WebContextContainer();
            }
        }

        public object this[string key]
        {
            get { return ContextContainer[key]; }
            set { ContextContainer[key] = value; }
        }
    }
}